package com.boot.controller;

import com.boot.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index(Model model){
        model.addAttribute("userName","唐三");

        return "index";//转发到页面...
    }

    @RequestMapping("/index2")
    public String index2(HttpServletRequest request, HttpSession session){
        request.setAttribute("myReq","李四");
        session.setAttribute("user","User对象....");
        request.getServletContext().setAttribute("appName","系统名称....");
        return "index2";
    }

    @RequestMapping("/index3")
    public String index3(Model model){

        User user = new User();
        user.setId(1L);
        user.setUserName("李四");
        user.setPassword("123456");

        model.addAttribute("user",user);

        return "index3";
    }

    @RequestMapping("/home")
    public String home(String userName,String password,Model model){
        System.out.println("userName = " + userName);
        System.out.println("password = " + password);
        model.addAttribute("userName",userName);
        model.addAttribute("password",password);
        return "home";
    }

}
